package drive.Service.ServiceFormat;

import com.aliyuncs.exceptions.ClientException;
import drive.Service.ServiceInterface.BaiduService;
import drive.pojo.AliyunOSSOperator;
import drive.pojo.NetWork;

import org.codehaus.jettison.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;
@Service
public class BaiduServiceA implements BaiduService {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    @Autowired
    NetWork netWork;
    @Override
    public String upload(MultipartFile file) throws IOException, ClientException {
        if (!file.isEmpty()) {
            // 生成唯一文件名
            String originalFilename = file.getOriginalFilename();
            String extName = originalFilename.substring(originalFilename.lastIndexOf("."));
            String uniqueFileName = UUID.randomUUID().toString().replace("-", "") + extName;
            System.out.println(uniqueFileName);
            // 上传文件
            String url = aliyunOSSOperator.upload(file.getBytes(), uniqueFileName);
            return url;
        }
        return "上传失败";
    }
    @Override
    public String detect(String url){
        return netWork.detect_animal(url);
    }

    @Override
    public String Plant_detect(String url){
        return netWork.Plant_detect(url);
    }

    @Override
    public String getKeyWord(String title, String content) throws IOException, JSONException {
       return netWork.getKeyWord(title,content);
    }


}
